package com.xiao.controller;

import com.xiao.entity.EmployeeEntity;
import com.xiao.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @_PackageName:com.xiao.controller
 * @_ClassName:EmployeeController
 * @_Description:
 * @_Author：笑老二
 * @_data 2020/12/14 20:34
 */
@RestController
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @RequestMapping("/findOne/{eid}")
    public EmployeeEntity findOneById(@PathVariable("eid") Integer eid) {
        return employeeService.findOneByEid(eid);
    }

    @RequestMapping("/insert")
    public EmployeeEntity insert() {
        EmployeeEntity employeeEntity = new EmployeeEntity(0, "xiaoLer", "123");
        employeeService.insert(employeeEntity);
        employeeEntity.setMessage("增加成功");
        return employeeEntity;
    }

    @RequestMapping("/delete/{eid}")
    public int delete(@PathVariable("eid") Integer eid) {
        employeeService.delete(eid);
        return 1;
    }

    @RequestMapping("/findAll")
    public List<EmployeeEntity> findAll() {
        List<EmployeeEntity> all = employeeService.findAll();
        return all;
    }

    @RequestMapping("/update/{eid}")
    public EmployeeEntity update(@PathVariable("eid") Integer eid) {
        EmployeeEntity update = null;
        try {
            update = employeeService.update(new EmployeeEntity(eid, "update", "123"));
            update.setMessage("修改成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return update;
    }


}
